package org.net
{
	import flash.events.*;
	import flash.events.ProgressEvent;
	import flash.media.Sound;
	import flash.net.URLRequest;
	import flash.errors.*
	
	import org.abcFrame.core.*;
	import org.net.*;
	import org.enmu.*;
	
	public class AbcLoaderSound
	{
		private var path:String
		private var responder:AbcResponder
		
		public function AbcLoaderSound(path:String,responder:AbcResponder)
		{
			this.path=path
			this.responder=responder
			
			var s:Sound = new Sound();
			s.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
			s.addEventListener(Event.COMPLETE, onLoadComplete);
			s.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			
			var req:URLRequest = new URLRequest(path);
			s.load(req);
		}
		
		function onLoadProgress(event:ProgressEvent):void
		{
			if(responder.onProgress!=null)responder.onProgress(event.bytesLoaded / event.bytesTotal);
		}
		
		function onLoadComplete(event:Event):void
		{
			try{
				
			   var localSound:Sound = event.target as Sound;
			   if(responder.onResult!=null)responder.onResult(localSound,path);
			   
			}catch(error:Error){
				
				AbcEventDispatcher.instance.dispatcher(AbcEventType.SOUNDEVENT,"completeHandler:处理"+path+"返回结果的responder函数出错了,可能是参数或是逻辑错误！"+error.message)
			
			}
			
		}
		
		function onIOError(event:IOErrorEvent)
		{
			
			AbcEventDispatcher.instance.dispatcher(AbcEventType.SOUNDEVENT,"completeHandler:处理"+path+"返回结果的responder函数出错了,可能是参数或是逻辑错误！"+event.text)
		
		}
		
		
	}
}








